 const db = require('mssql');
 const pool = require('./mssqlpool.js').pool;

 async function queryOrders() {
     let request = new db.Request(pool);
     let orders = await request.query('select top 10 * from OM_Order');
     console.log(pool.id);

     return orders.recordset;
 }

 async function findByListNo(listNo) {
     let orders = await new db.Request(pool)
         .input('ListNo', db.NVarChar, listNo)
         .query('select top 10 * from OM_Order where ListNo=@ListNo');

     return orders.recordset;
 }

 exports.getOrders = async function(req, res) {
     try {
         let orders = await queryOrders();
         res.json(orders);
     } catch (err) {
         console.log(err);
     }
 }

 exports.findByListNo = async function(req, res) {
     try {
         let listNo = req.params.listNo;
         let order = await findByListNo(listNo);

         res.json(order);
     } catch (err) {
         console.log(err);
     }
 }